<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>未关闭服务通知</title>
		<!-- css代码 start -->
		<link href="../../../css/mui.min.css" rel="stylesheet" />
		<link href="../../../css/global.css" rel="stylesheet" />
		<link href="../../../css/style.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../../css/mui.picker.css">
		<link rel="stylesheet" href="../../../css/mui.poppicker.css">
		<link rel="stylesheet" href="../../../css/task.css">
		<style>
			.mui-checkbox input[type=checkbox], .mui-radio input[type=radio]{
				top: 8px;
				right: -10px;
			}
			
			.d_int_tp{
				border: 0 !important;
				margin-top: 6px !important;
			}
			.details_con .btm .selectBtn {
			    line-height: 28px;
			    color: #ffffff;
			    background: #ea1e1a;
			}
			
			.item_box .item .text{
				margin: 5px auto;
			}
			.item_box .item .text span.cen{
				margin-left:0;
			}
			.item_box .item .text span{
				width: auto;
			}
			.select-tzstate{
				width: 100%;
				border: 0;
				color: #a9a9a9;
				font-size: 16px;
				text-align: left;
				padding: 15px;
			}
			.mui-bar-nav{
				box-shadow: 0 1px 6px #ea1e1a;
			}
		</style>
		<!-- css代码 end -->
	</head>

	<body>
		<!-- html代码 start -->
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">未关闭服务通知</h1>
		</header>
		<div class="mui-content">
			
			<div class="details_con select_con" id="search">
				<div class="clum">
					<input type="text" class="d_int_tp" id="customerName" placeholder="输入客户名称" />
				</div>
				<div class="clum">
					<!-- <input type="text" class="d_int_tp" id="serviceType" placeholder="输入服务类型" /> -->
					<span class="txt" style="width: 100%;">
						<input type="hidden" id="serviceTypeValue" />
						<button id='serviceType' class="mui-btn mui-btn-block mui-btn-select select-tzstate" type='button'>请选择服务子类型</button>
					</span>
				</div>
				<div class="clum">
					<input type="text" class="d_int_tp" id="instrumentSerialNumber" placeholder="输入仪器序列号" />
				</div>
				<div class="clum">
					<!-- <input type="text" class="d_int_tp" id="state" placeholder="服务通知状态" /> -->
					<!-- <span class="name">Error代码类别</span> -->
					<span class="txt" style="width: 100%;">
						<input type="hidden" id="stateValue" />
						<button id='state' class="mui-btn mui-btn-block mui-btn-select select-tzstate" type='button'>请选择服务通知状态</button>
					</span>
				</div>
				<div class="btm autoHeight">
					<p class="selectBtn" id="searchBtn" onclick="initData()">查 询</p>
				</div>
			</div>
			
			<div class="details_con" style="margin: 30px 0 0 0;">
				<div class="item_box" id="itemBox">
				</div>
			</div>
			<div style="height: 50px;"></div>
		</div>
		<!-- html代码 end -->
		
		<!-- js代码 start -->
		
		<!-- 基础js start -->
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/utils/h.js"></script>
		<script src="../../../js/constant.js"></script>
		<script src="../../../js/common.js"></script>
		<script src="../../../js/utils/base64.js"></script>
		<script src="../../../js/utils/md5.js"></script>
		<script src="../../../js/utils/sortMap.js"></script>
		<script src="../../../js/utils/http.js"></script>
		<script src="../../../js/app.js"></script>
		<!-- 基础js end -->
		<script src="../../../js/mui.picker.js"></script>
		<script src="../../../js/mui.poppicker.js"></script>
		<script src="../../../js/utils/rolldate.min.js"></script>
		<script type="text/javascript" charset="utf-8">
			function initData(){
				app.showWaiting('加载中...')
				
				var customerName = h("#customerName").val();
				var serviceType = h("#serviceType").html();
				if(serviceType=='请选择服务子类型'){
					serviceType = ""
				}
				var instrumentSerialNumber = h("#instrumentSerialNumber").val();
				var state = h("#stateValue").val();
				
				ajaxGet(BASE_URL + "cc/notice/getTeamServiceNotice", {
					"enginnerId": app.getUser().enginnerId,
					// "appState": '2',
					"customerName": customerName,
					"serviceType": serviceType,
					"instrumentSerialNumber": instrumentSerialNumber,
					"state": state
				}, function(data) {
					app.closeWaiting()
					console.log(JSON.stringify(data))
					if (data.code === 200) {
						var str = '';
						if (data.data && data.data.length > 0) {
							 for(var c = 0;c<data.data.length;c++){
								 //默认0待接受，1已接受，2已签到，3已签离，4已完成,5自动签离，6已拒绝
								planState = data.data[c].planState;
								var customerName = data.data[c].customerName ? data.data[c].customerName : "";
								var createTime = data.data[c].createTime ? data.data[c].createTime : "";
								var serviceType = data.data[c].subServiceType ? data.data[c].subServiceType : "";
								var enginnerType = data.data[c].enginnerType ? data.data[c].enginnerType : "";
								str += '<div class="item" onclick="jumpPage(\''+planState+'\',\''+data.data[c].id+'\',\''+data.data[c].serviceNo+'\',\''+data.data[c].planId+'\',\''+data.data[c].subServiceType+'\',\''+data.data[c].isCheck+'\')">';
								str += '<div class="bar">';
								str += '<span class="number">'+data.data[c].serviceNo+'<img src="../../../images/icon_204.png" /></span>';
								// if(planState != '4'){
								// 	str += '<span class="vip">指派FSE</span>';
								// }
								str += '</div>';
								str += '<div class="text">';
								str += '<span class="cen" style="color: #333;">'+customerName+'</span>';
								str += '</div>';
								str += '<div class="type">';
								str += '<p><div class="lpl">提交时间：</div><span>'+createTime+'</span><img src="../../../images/icon_202.png"/></p>'
								str += '<p><div class="lpl">客户类型：</div><span>'+enginnerType+'</span><img src="../../../images/icon_203.png"/></p>'
								str += '<p><div class="lpl">服务子类型：</div><span>'+serviceType+'</span><img src="../../../images/icon_203.png"/></p>'
								
								if(planState == '0'){
									planStateName = "待接受";
								}else if(planState == '1'){
									planStateName = "已接受";
								}else if(planState == '2'){
									planStateName = "已签到";
								}else if(planState == '3'){
									planStateName = "已签离";
								}else if(planState == '4'){
									planStateName = "已完成";
								}else if(planState == '5'){
									planStateName = "自动签离";
								}else if(planState == '6'){
									planStateName = "已拒绝";
								}
								str += '<p><div class="lpl">状态：</div><span>'+planStateName+'</span><img src="../../../images/icon_205.png"/></p>';
								str += '</div>';
								str += '</div>';
							 }
							 h('#itemBox').html(str);
						}else{
							var html = '<div class="nodata">—— 暂无数据 ——</div>';
							h("#itemBox").html(html);
						}
					} else {
						var html = '<div class="nodata">—— 暂无数据 ——</div>';
						h("#itemBox").html(html);
						app.toast(data.msg);
					}
				}, function(errorMsg) {
					app.closeWaiting()
					var html = '<div class="nodata">—— 暂无数据 ——</div>';
					h("#itemBox").html(html);
					app.toast("数据获取失败，请检查网络连接");
				});
			}
			
			(function($, doc) {
				var planState;
				var planStateName;
				$.init();
		
				$.plusReady(function() {
					var self = plus.webview.currentWebview();
					initData()	
					
					h("#state").tap(function() {
						var statePicker = new mui.PopPicker();
						statePicker.setData([{
							value: '',
							text: '请选择服务通知状态'
						}, {
							value: '0',
							text: '待接受'
						}, {
							value: '1',
							text: '已接受'
						}, {
							value: '2',
							text: '已签到'
						}, {
							value: '3',
							text: '已签离'
						}, {
							value: '4',
							text: '已完成'
						}, {
							value: '5',
							text: '自动签离'
						}]);
						statePicker.show(function(items) {
							console.log(JSON.stringify(items[0]));
							h('#state').html(items[0].text)
							h("#stateValue").val(items[0].value)
							statePicker.dispose()
						});
					})
					
					// 服务子类型下拉
					h('#serviceType').tap(function() {
						var userPicker = new $.PopPicker();
						ajaxGetJson(BASE_URL + 'cc/dict/selectCCDict', {
							tableName: 'snsubtype',
							engineerId: app.getUser().enginnerId
						}, function(data) {
							console.log(JSON.stringify(data))
							if (!data) {
								app.toast("无下拉内容")
								return
							}
							// 数组指定位置插入数据
							data.splice(0, 0, {"text":"请选择服务子类型","value":""});
							userPicker.setData(data);
							userPicker.show(function(items) {
								h('#serviceType').html(items[0].text)
								h('#serviceTypeValue').val(items[0].value)
								userPicker.dispose()
							});
						});
					});
					
					h('.mui-action-back').tap(function () {
						var noticeMenu=plus.webview.getWebviewById('view/service/notice/noticeMenu.html');
						if(noticeMenu){
							noticeMenu.evalJS('getNoticeCount()')
						}
					});
				});
			}(mui, document));
			
			// 页面跳转方法
			function jumpPage(planState, ServiceNoticeId, serviceNo, planId, subServiceType, isCheck){  //根据不同状态进入不同页面
				// 不同的状态跳转到不同的页面
				if (planState == 0) { // 待接受
					app.jumpTo("/view/service/accept/details.html", "view/service/accept/details.html", {
						ServiceNoticeId: ServiceNoticeId,
						serviceNo: serviceNo,
						planId: planId
					});
				} else if (planState == 1) { // 已接受
					//已接受进入签到页面
					app.jumpTo('/view/service/notice/signIn.html', 'view/service/notice/signIn.html', {
						ServiceNoticeId: ServiceNoticeId,
						serviceNo: serviceNo,
						planId: planId
					})
				} else if (planState == 2) { // 已签到
					//已签到  判断服务类型是安装还是非安装
					if (subServiceType == "安装") {
						//判断是否写日志
						ajaxPost(BASE_URL + "cc/ServiceLog/selectServiceLogList", {
							"stPlanId": planId
						}, function(data) {
							if (data.code === 200) {
								//如果是安装单，判断是否已核对
								if (isCheck == "2") { //已核对
									//判断有没有日志
									if (data.data && data.data.length > 0) {
										app.jumpTo("/view/service/notice/signOutAddReport.html", "view/service/notice/signOutAddReport.html", {
											ServiceNoticeId: ServiceNoticeId,
											serviceNo: serviceNo,
											planId: planId
										});
									} else {
										app.jumpTo('/view/service/notice/signOut.html', 'view/service/notice/signOut.html', {
											ServiceNoticeId: ServiceNoticeId,
											serviceNo: serviceNo,
											planId: planId
										});
									}
								} else { //跳转到核对页面
									app.jumpTo('/view/service/checkInstrument/checkInstrument.html',
										'view/service/checkInstrument/checkInstrument.html', {
											serviceNo: serviceNo,
											ServiceNoticeId: ServiceNoticeId,
											planId: planId
										})
								}
							} else {
								app.toast('查询日志失败')
							}
						}, function(errorMsg) {
							app.toast('查询日志失败')
						});
				
						// app.jumpTo('/view/service/checkInstrument/checkInstrument.html','/view/service/checkInstrument/checkInstrument.html',{ServiceNoticeId:ServiceNoticeId,serviceNo:serviceNo})
					} else {
						app.jumpTo('/view/service/notice/signOut.html', 'view/service/notice/signOut.html', {
							ServiceNoticeId: ServiceNoticeId,
							serviceNo: serviceNo,
							planId: planId
						})
					}
				} else if (planState == 3) { // 已签离
					//已签离 跳转签到添加报告页面
					app.jumpTo('/view/service/notice/signInAddReport.html', 'view/service/notice/signInAddReport.html', {
						ServiceNoticeId: ServiceNoticeId,
						serviceNo: serviceNo,
						planId: planId
					})
				} else if (planState == 4 || planState == 5) { // 已完成 自动签离
					//已完成 自动签离 先判断是否有日志  没有进日志页  有进报告页
					ajaxGet(BASE_URL + "cc/ServiceLog/getServiceLogList", {
						"enginnerId": app.getUser().enginnerId,
						"planId": planId
					}, function(data) {
						console.log(JSON.stringify(data))
						if (data.code == 200) {
							if (data.data.length == 0) {
								app.jumpTo("/view/service/serviceLog/logAdd.html", "view/service/serviceLog/logAdd.html", {
									serviceNoticeId: ServiceNoticeId,
									serviceNo: serviceNo,
									planId: planId,
									listName: "checkedOutList"
								});
							} else { //进报告页面
								app.jumpTo("/view/service/notice/signOutVisitAgain.html", "view/service/notice/signOutVisitAgain.html", {
									ServiceNoticeId: ServiceNoticeId,
									serviceNo: serviceNo,
									planId: planId,
									complete: 1
								});
							}
						} else {
							app.toast(data.msg)
						}
					}, function(errorMsg) {
						app.toast(errorMsg)
					});
				}
			}
		</script>
		<!-- js代码 end -->
	</body>

</html>
